<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [10, 20, 30, 40, 20]

        //知道找到第一个返回值为true的成员，然后返回该成员，如果没有符合条件的成员，则返回undefined
        //arr.find(()=>{})
        let newVal = arr.find((val, index) => {
            /* console.log(val);
            console.log(index); */
            if (val + 20 === 40) return true
        })

        let newVal1 = arr.find((val, index) => val > 25)
        let newVal2 = arr.find((val, index) => index == 1)
        console.log(newVal)
        console.log(newVal1)
        console.log(newVal2)


        //findIndex  返回符合条件的成员的索引 如果没有则返回-1
        let arr1 = [10, 20, 30, 40, 50]
        let newIndex = arr1.findIndex((val, index) => {
            if (val > 40) return true
        })
        let newIndex1 = arr1.findIndex((val, index) => val === 10)
        let newIndex2 = arr1.findIndex((val, index) => val >= 60)
        console.log(newIndex)
        console.log(newIndex1)
        console.log(newIndex2)
    </script>
</body>

</html>